package com.fengzuxiao.weatherdemo.lr;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.fengzuxiao.weatherdemo.MainActivity;
import com.fengzuxiao.weatherdemo.R;
import com.fengzuxiao.weatherdemo.UserService;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by 17929 on 2020/6/9.
 */

public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
    private Button loging;
    private Button regist;
    private EditText edt;
    private  EditText edt_1;
    private TextView edt_6;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        init();

    }

    private void init() {
        loging= findViewById(R.id.loging);
        regist=  findViewById(R.id.regist);
        edt= findViewById(R.id.edt);
        edt_1=  findViewById(R.id.edt_1);
        edt_6=  findViewById(R.id.edt_6);
        loging.setOnClickListener(this);
        regist.setOnClickListener(this);
        edt_6.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.loging:
                String name = edt.getText().toString().trim();
                String pass = edt_1.getText().toString().trim();
                UserService uService=new UserService(this);
                boolean flag=uService.login(name, pass);


                if (TextUtils.isEmpty(name)&&TextUtils.isEmpty(pass)){
                    Toast.makeText(this,"账号或密码为空",Toast.LENGTH_LONG).show();
                }
               else if(flag){
                    Intent intent=new Intent(this, MainActivity.class);
                    startActivity(intent);
                    Toast.makeText(this, "登陆成功", Toast.LENGTH_LONG).show();
                }
                else {
                    Toast.makeText(this, "手机号或密码输入错误！", Toast.LENGTH_SHORT).show();
                }
                break;
            case  R.id.regist:
                Intent inten1=new Intent(this,RegistActivity.class);
                startActivity(inten1);
                break;
            case  R.id.edt_6:
                Intent intent2=new Intent(this,ChangeActivity.class);
                startActivity(intent2);
        }
    }
}

